﻿Imports System.Data.SqlClient
Public Class clsARInvoice

    Function Create_ARInvoice(ByRef sErrDesc As String) As Long

        Dim sFuncName As String = String.Empty
        Dim oARInvoice As AE_EASIPOS_INTEGRATION_DLL.clsARInvoice = New AE_EASIPOS_INTEGRATION_DLL.clsARInvoice
        Dim oDataSetInvoice As DataSet = Nothing

        Try

            sFuncName = "Create_ARInvoice()"
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting function", sFuncName)

            'Getting the Parameter Values from App Cofig File
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling GetSystemIntializeInfo()", sFuncName)
            If GetSystemIntializeInfo(p_oCompDef, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)


            P_sConString = String.Empty
            P_sConString = "Data Source=" & p_oCompDef.p_sServerName & ";Initial Catalog=" & p_oCompDef.p_sIntDBName & ";User ID=" & p_oCompDef.p_sDBUserName & "; Password=" & p_oCompDef.p_sDBPassword
            AE_EASIPOS_INTEGRATION_DLL.P_sConString = P_sConString

            'Getting the Data from Invoice Table as DataSet
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ARInvoice_DataSet()", sFuncName)
            oDataSetInvoice = oARInvoice.ARInvoice_DataSet(P_sConString)

            If Not oDataSetInvoice Is Nothing Then

                'Function to connect the Company
                If p_oCompany Is Nothing Then
                    If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ConnectToTargetCompany()", sFuncName)
                    If ConnectToTargetCompany(p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)
                End If

                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling ARInvoice()", sFuncName)
                If oARInvoice.ARInvoice(oDataSetInvoice, p_oCompany, sErrDesc) <> RTN_SUCCESS Then Throw New ArgumentException(sErrDesc)

            End If

            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with SUCCESS", sFuncName)
            Create_ARInvoice = RTN_SUCCESS
        Catch ex As Exception
            Call WriteToLogFile(ex.Message, sFuncName)
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Completed with ERROR", sFuncName)
            Create_ARInvoice = RTN_ERROR
        End Try

    End Function

End Class
